
import React from 'react'
import { useSelector } from 'react-redux';
import { Form, Input, Button, Checkbox, message } from 'antd';
import { httpAddVideoComment } from '../../apis';
const { TextArea } = Input;


export default function ShowVideoInput(props) {
    const user = useSelector(state=>state.user);
    const setRefresh = props.setRefresh;
    const video = props.video;

    const onFinish = async (values: any) => {
        values.time = new Date().getTime();
        values.videoId = video.videoId;
        values.userId = user.userId;
        let res = await httpAddVideoComment(values);
        if(res) {
            message.success("发表评论成功");
            setRefresh(true);
        } else {
            message.error("发表评论失败");
        }
    };

    const onFinishFailed = (errorInfo: any) => {
        console.log('Failed:', errorInfo);
    };
    return (
        <div className='ShowVideoInput-container'>
            <Form
            name="basic"
            wrapperCol={{ span: 22}}
            initialValues={{ remember: true }}
            onFinish={onFinish}
            onFinishFailed={onFinishFailed}
            autoComplete="off"
            >
            <Form.Item
                name="content"
                rules={[{ required: true, message: '请输入你的内容' }]}
            >
                <TextArea rows={4} placeholder="maxLength is 6" maxLength={30} />
            </Form.Item>


            <Form.Item wrapperCol={{ push: 20}}>
                <Button type="primary" htmlType="submit">
                    Submit
                </Button>
            </Form.Item>
            </Form>
        </div>
    )
}
